<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" />
<link href="../../css/themes/default.css" rel="stylesheet" type="text/css"/>
<link href="../../css/themes/mac_os_x.css" rel="stylesheet" type="text/css"/>
<link href="../../css/themes/alphacube.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../js/prototype.js"></script>
<script type="text/javascript" src="../../js/scriptaculous.js"></script>
<script type="text/javascript" src="../../js/page.js"></script>
<script type="text/javascript" src="../../js/window.js"></script>
<script type="text/javascript" src="../../js/window_effects.js"></script>
<script type="text/javascript">
var win;
var messages = new Array('', 'Documento inserito con successo', 'Documento cancellato con successo', 'Documento modificato con successo');
function show_div(div){
	if($(div).style.display == "none")
		$(div).appear({ duration: 1.0 });
	else
		$(div).fade({ duration: 1.0 });
}

function doc(id, tipo){
    win = new Window({className: "mac_os_x", url: "dettaglio_documento.php?id="+id+"&tipo="+tipo+"&area=admin",  width:650, height:450, zIndex: 100, resizable: true, title: "Dettaglio documento", showEffect:Effect.Appear, hideEffect: Effect.Fade, draggable:true, wiredDrag: true});
	win.showCenter(false);
}
</script>
</head>
<body <?php if(isset($_REQUEST['msg'])){ ?>onload="openInfoDialog(messages[<?php print $_REQUEST['msg'] ?>])"<?php } ?>>
<div id="header">
<div class="wrap">
<?php include "../header.php" ?>
	</div>
</div>
<div class="wrap">
<div id="main" style="background-color: #FFFFFF; padding-bottom: 30px; width: 100%">
    <form>
    <p style="padding-top: 16px; padding-bottom: 16px; color: #000000; font-size: 12px; font-weight: bold; text-align: center">Gestione documenti</p>
    <?php
$x = 0;
while($type = $res_type->fetch_assoc()){
	if($x > 0)
		print("</div>");
?>
<p style="width: 90%; margin-left: auto; margin-right: auto; border-bottom: 1px solid gray; <?php if($x > 0) print ("margin-top: 20px") ?>">
<a href='#' onclick="show_div('tipo<?php print $type['id'] ?>')" style='font-size: 12px; font-weight: normal; margin-left: 0px; text-decoration: none'>
	<?php print $type['commento'] ?>
</a>
<a style="float: right; margin-right: 20%; text-decoration: none" href="#" onclick="doc(0, <?php print $type['id'] ?>)">Nuovo documento</a>
</p>
<div id="tipo<?php print $type['id'] ?>" style="display: none; width: 80%; margin: auto">
<?php
	$sel_docs = "SELECT documents.*, anni.descrizione FROM documents, document_types, anni WHERE doc_type = document_types.id AND document_types.id = ".$type['id']." AND anni.id_anno = anno_scolastico ORDER BY anno_scolastico DESC, data_upload DESC";
	//print $sel_docs;
	$res_docs = $db->execute($sel_docs);
    $id_anno = 0;
	if($res_docs->num_rows > 0){
		while($doc = $res_docs->fetch_assoc()){
			if($doc['link'] != "")
				$link = $doc['link'];
			else
				$link = $doc['file'];
			if($doc['doc_type'] != 4)
				$ab = $doc['abstract'];
			else
				$ab = $doc['titolo'];
			if($id_anno != $doc['anno_scolastico']){
				if($id_anno != 0)
					print("</div> <!-- chiusura anno -->");
?>
	
	<p style="margin-left: 10px; height: 15px">
		<a href="#" onclick="show_div('tipo<?php print $type['id'] ?>_anno<?php print $doc['anno_scolastico'] ?>')" style='text-decoration: none; font-weight: normal; margin-left: 15px'>Anno scolastico <?php print $doc['descrizione'] ?></a>
	</p>
	<div id="tipo<?php print $type['id'] ?>_anno<?php print $doc['anno_scolastico'] ?>" style="display: none; margin-left: 15px">
<?php
			}
			$id_anno = $doc['anno_scolastico'];
?>
	<p style="margin-left: 25px; height: 15px">
		<a href="#" onclick="doc(<?php print $doc['id'] ?>, <?php print $type['id'] ?>)" style="text-decoration: none; "><?php print $ab ?></a>
	</p>
<?php
		}
		print("</div> <!-- chiusura tipo -->");
	}
	$x++;
}
print("</div>");
?>
    <div style="text-align: right; width: 90%; margin-top: 50px; margin-bottom: 30px">
    	<a href="../index.php" style="margin-right: 20px">Torna al menu</a>
    </div>
    </form>
    </div>
        <div id="footer">
			<p>Design: Luka Cvrk - <a href="http://www.solucija.com" title="Free Web Templates">Solucija</a></p>
		</div>
	</div>
</body>
</html>